package com.hh.us.mongo.morphia.util;

import com.github.jmkgreen.morphia.query.Query;

public class MongoPaginationUtil {

	public static <T> Query<T> generatePaginationQuery(Query<T> query,
			int pPage, int pPageSize) {
		pPage = pPage < 1 ? 1 : pPage;
		pPageSize = pPageSize < 1 ? 10 : pPageSize;
		int offset = (pPage - 1) * pPageSize;
		query.offset(offset);
		query.limit(pPageSize);
		return query;
	}

}
